//
//  ViewController.m
//  VersionUpdating
//
//  Created by Dxc_iOS on 2018/7/12.
//  Copyright © 2018年 代星创. All rights reserved.
//

#import "ViewController.h"
#import "VersionUpdating.h"
#import "QYAlertView.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
//    检测更新是放在首页的
    [self updateVersions];//检查更新版本
}
#pragma mark---- updateVersions
-(void)updateVersions{
    //    appId，bundelId，随便传一个 或者都传nil 即可实现检测版本
    [VersionUpdating app_versionUpdatingWithAPPID:nil withBundleId:nil block:^(NSString *currentVersion, NSString *storeVersion, NSString *openUrl, BOOL isUpdate) {
        if (isUpdate) {
            [self showAlertViewTitle:@"温馨提示" subTitle:[NSString stringWithFormat:@"检测到新版本%@,是否更新？",storeVersion] openUrl:openUrl];
            
        }else{
            NSLog(@"当前版本%@,商店版本%@，不需要更新",currentVersion,storeVersion);
        }
        
    }];
    
}
-(void)showAlertViewTitle:(NSString *)title subTitle:(NSString *)subTitle openUrl:(NSString *)openUrl{
    
    
    [QYAlertView showAlertWithTitle:title message:subTitle confirmTitle:@"更新" cancelTitle:@"取消" preferredStyle:Alert confirmHandle:^{
//        更新
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:openUrl] options:@{} completionHandler:^(BOOL success) {
        }];
    } cancleHandle:^{
//不更新
//        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:openUrl] options:@{} completionHandler:^(BOOL success) {
//
//        }];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
